/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SelecionarDado.java
 *
 * Created on 27/06/2010, 19:54:22
 */

package fronteira;

import Conexao_BD.Conexao_BD;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import Conexao_BD.Conexao_BD;
import java.util.Vector;

/**
 *
 * @author Guilherme
 */
public class SelecionarDado extends javax.swing.JFrame {

    /** Creates new form SelecionarDado */

    Conexao_BD conexao;
    String selecionado = "";
    public SelecionarDado() {
        initComponents();
    }


     public SelecionarDado(String tipoDado) {
         String consulta = "";
         String coluna = "";
         ResultSet rs;
         Vector<String> dados = new Vector<String>();
         if (tipoDado.matches("Fabricante")){
            consulta = "select * from fabricante";
            coluna = "fab_nome";
         }else
         if (tipoDado.matches("Classe")){
            consulta = "select * from classe";
            coluna = "cs_nome";
         }else
         if (tipoDado.matches("Subclasse")){
            consulta = "select * from subclasse";
            coluna = "sub_nome";
         }else
         if (tipoDado.matches("Tipo")){
            consulta = "select * from tipo";
            coluna = "tp_nome";
         }
        try {
            conexao = new Conexao_BD("bcc.unifal-mg.edu.br/projeto2","projeto2","projeto2bcc");
            rs = conexao.consulta(consulta);
            while (rs.next()){
                dados.add(rs.getString(coluna));
            }
        } catch (SQLException ex) {
            Logger.getLogger(SelecionarDado.class.getName()).log(Level.SEVERE, null, ex);
        }



        initComponents();
        jList1.setListData(dados);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Selecione o item desejado:");

        jScrollPane1.setViewportView(jList1);

        jButton1.setText("Selecionar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jButton1))
                .addContainerGap(131, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabel1)
                .addGap(38, 38, 38)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(23, 23, 23))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        System.out.println(jList1.getSelectedValue().toString());
        selecionado = jList1.getSelectedValue().toString();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SelecionarDado("Tipo").setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
